#include "StdAfx.h"
#include "DialogMap.h"
#include "GameDialogue.h"

CDialogMap::CDialogMap(void)
{
}

CDialogMap::~CDialogMap(void)
{
}

void CDialogMap::Initialize(int Depth)
{
	
}

bool CDialogMap::AddDialogue(CGameDialogue* pGameDialog, int StrPos, wchar_t Letter, int Depth)
{
	if(StrPos + 1 < Depth)
	{
		mapGameDialogueMap::iterator iter;
		iter = m_mapGameDialogueMap.find(Letter);

		if(iter == m_mapGameDialogueMap.end())
		{
			CDialogMap* pDialogMap = new CDialogMap();

			if(m_mapGameDialogueMap.insert(mapGameDialogueMap::value_type(Letter, pDialogMap)).second != true)
			{
				return false;
			}

			StrPos += 1;
			wstring OneWideChar = pGameDialog->m_OriginalDialogue.substr(StrPos, StrPos+ 1);

			return pDialogMap->AddDialogue(pGameDialog, StrPos, *OneWideChar.c_str(), Depth);

		}
		else
		{
			StrPos += 1;
			wstring OneWideChar = pGameDialog->m_OriginalDialogue.substr(StrPos, StrPos+ 1);

			return iter->second->AddDialogue(pGameDialog, StrPos, *OneWideChar.c_str(), Depth);
		}
	}
	else if(StrPos + 1 == Depth)
	{
		if(m_mapGameDialogue.insert(mapGameDialogue::value_type(pGameDialog->m_OriginalDialogue, pGameDialog)).second != true)
		{
			return false;
		}

		return true;
	}

	return false;
}

bool CDialogMap::GetTranslateDialogue(wstring szOriginalString, wstring& TranslatedMessage, int StrPos, wchar_t Letter, int Depth)
{
	if(StrPos + 1 < Depth)
	{
		mapGameDialogueMap::iterator iter;
		iter = m_mapGameDialogueMap.find(Letter);

		if(iter == m_mapGameDialogueMap.end()) 
		{
			return false;

		}
		else
		{
			StrPos += 1;
			wstring OneWideChar = szOriginalString.substr(StrPos, StrPos+ 1);

			return iter->second->GetTranslateDialogue(szOriginalString, TranslatedMessage, StrPos, *OneWideChar.c_str(), Depth);
		}
	}
	else if(StrPos + 1 == Depth)
	{
		mapGameDialogue::iterator iter;
		iter = m_mapGameDialogue.find(szOriginalString);

		if(iter != m_mapGameDialogue.end())
		{
			TranslatedMessage = iter->second->m_TranslatedDialogue;
			return true;
		}
	}

	return false;
}